/**
* @Title: Java2JsonArray.java
* @Description: ${TODO} 类描述
* @Copyright 方正国际软件有限公司,Inc.Allrightsreserved.
 * @author Founder 
* @date 2011-7-25 12:51:23
* @version V1.0 
 */
package com.founder.android.parser;

import java.lang.reflect.Array;
import java.util.Collection;
import java.util.Iterator;

import org.json.JSONArray;
import org.json.JSONException;

public class Java2JsonArray extends JSONArray {
	
    public Java2JsonArray(Object array) throws JSONException {
        super();
        if (array.getClass().isArray()) {
            int length = Array.getLength(array);
            for (int i = 0; i < length; i += 1) {
                this.put(Java2Json.wrap(Array.get(array, i)));
            }
        } else {
            throw new JSONException("JSONArray initial value should be a string or collection or array.");
        }
    }
    
    @SuppressWarnings("unchecked")
	public Java2JsonArray(Collection collection) {
    	super();
		if (collection != null) {
			Iterator iter = collection.iterator();;
			while (iter.hasNext()) {
			    Object o = iter.next();
                this.put(Java2Json.wrap(o));  
			}
		}
    }

}